<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>删除会员-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <base href="http://localhost:8080/"/>
    <link rel="stylesheet" href="css/font.css"/>
    <link rel="stylesheet" href="css/weadmin.css"/>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-nav">
    <span class="layui-breadcrumb">
      <a href="javascript:;">首页</a> <a href="javascript:;">会员管理</a>
      <a href="javascript:;"><cite>删除会员</cite></a>
    </span>
    <a class="layui-btn layui-btn-sm" style="margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i>
    </a>
</div>
<div class="weadmin-body">
    <div class="layui-row">
        <div class="demoTable">
            会员搜索：
            <div class="layui-inline">
                <input class="layui-input" name="keyword" placeholder="搜索用户名,昵称或邮箱" id="demoReload" autocomplete="off">
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
    </div>
    <div class="weadmin-block demoTable">
        <button class="layui-btn layui-btn-danger" data-type="batchRestore">
            <i class="layui-icon layui-icon-delete"></i>批量恢复
        </button>
    </div>
    <!-- 表单数据 -->
    <table class="layui-hide" id="member-table" lay-filter="member-table"></table>
    <!-- 操作栏 -->
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="restore">恢复</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src=js/eleDel.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['table', 'jquery'], function () {
        var table = layui.table,
            $ = layui.jquery;

        table.render({
            elem: '#member-table'         // 显示表单数据的div的id
            , url: 'member/manage/deleted/list' // 请求url
            , title: '删除用户表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 60, fixed: 'left', sort: true}
                , {field: 'username', title: '用户名', width: 140}
                , {field: 'name', title: '用户昵称', width: 140}
                , {field: 'sex', title: '性别', width: 75}
                , {field: 'title', title: '职位', width: 120, sort: true}
                , {field: 'department', title: '部门', width: 100, sort: true}
                , {field: 'gmtCreate', title: '加入时间', width: 180, sort: true}
                , {field: 'deleteToken', title: '删除时间', width: 180, sort: true}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 130}
            ]]
            , id: 'memberList'
            , page: true
        });

        //监听行工具事件
        table.on('tool(member-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确认要完全删除吗', function (index) {
                    // 发送删除请求
                    $.ajax({
                        url: 'http://localhost:8080/member/manage/deleted/completeDelete',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            "id": data.id
                        },
                        success: function (res) {
                            if (res.result === "SUCCESS") {
                                console.log('删除成功');
                                layer.msg("删除成功！", {
                                    icon: 1,
                                    time: 500,
                                    end: function () {
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.msg(res.message);
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'restore') {
                // 恢复操作
                layer.confirm('确认恢复账户吗', function (index) {
                    // 发送恢复请求
                    $.ajax({
                        url: 'http://localhost:8080/member/manage/deleted/restore',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            "id": data.id
                        },
                        success: function (res) {
                            if (res.result === "SUCCESS") {
                                console.log('恢复成功');
                                layer.msg("恢复成功！", {
                                    icon: 1,
                                    time: 500,
                                    end: function () {
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.msg(res.message);
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });


        // 搜索事件
        var active = {
            reload: function () {
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('memberList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        keyword: demoReload.val()
                    }
                });
            },

            batchRestore: function () { //获取选中数据
                var checkStatus = table.checkStatus('memberList')
                    , data = checkStatus.data;
                var restoreId = [];
                for (let i = 0; i < data.length; i++) {
                    restoreId.push(data[i].id);
                }
                // 执行批量删除
                layer.confirm('确认要恢复吗？', function (index) {
                    $.ajax({
                        url: 'http://localhost:8080/member/manage/deleted/batch/restore',
                        type: 'POST',
                        dataType: 'json',
                        data: "list=" + restoreId,
                        success: function (res) {
                            if (res.result === "SUCCESS") {
                                console.log('批量恢复成功');
                                layer.msg('恢复成功!', {
                                    icon: 1,
                                    time: 500,
                                    end: function () {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.msg(res.message);
                            }
                        }
                    });
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>

</html>